<template>
  <el-container>
    <el-header style="background-color:#eff2f7" class="top">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item :to="{ path: '/orderList' }">数据管理</el-breadcrumb-item>
        <el-breadcrumb-item>订单列表</el-breadcrumb-item>
      </el-breadcrumb>
      <div class="block">
        <el-avatar :size="50" :src="circleUrl"></el-avatar>
        <div class="poputs">
          <div @click="tzHome">首页</div>
          <div @click="tzLogin">退出</div>
        </div>
      </div>
    </el-header>
    <el-main style="background-color:#fff">
      <el-table :data="tableData" style="width: 100%;border: 1px solid #eef1f6">
        <el-table-column type="expand">
          <template slot-scope="props">
            <el-form label-position="left" inline class="demo-table-expand">
              <el-form-item label="用户id">
                <span>{{ props.row.user_id }}</span>
              </el-form-item>
              <el-form-item label="店铺名称">
                <span>{{ props.row.restaurant_name}}</span>
              </el-form-item>
              <el-form-item label="地址 id">
                <span>{{ props.row.address_id }}</span>
              </el-form-item>
              <el-form-item label="店铺 ID">
                <span>{{ props.row.restaurant_id}}</span>
              </el-form-item>
              <el-form-item label="下单时间">
                <span>{{ props.row.formatted_created_at }}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column label="订单 ID" prop="id"></el-table-column>
        <el-table-column label="总价格" prop="basket.packing_fee.price"></el-table-column>
        <el-table-column label="订单状态" prop="status_bar.title"></el-table-column>
      </el-table>
      <el-pagination
        class="page"
        background
        layout="total,prev, pager, next"
        :total="tb[0].id-140"
        @size-change="handleSizeChange()"
        @current-change="handleCurrentChange"
        :current-page="currentPage1"
        :page-size="20"
      ></el-pagination>
    </el-main>
  </el-container>
</template>
<style>
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
.page {
  margin: 20px;
  /* margin-bottom: 30px; */
}
</style>
<script>
export default {
  data() {
    return {
      circleUrl: "https://img01.sogoucdn.com/app/a/100520093/fb41c7c77a2454f7-01eba5833e7e38bc-11cc0200d4b834a0dddb28091fd46806.jpg",
      offset: 0,
      limit: 20,
      tableData: [{
      }],
      tb: [{}],
      currentPage1: 1,

    };
  },
  methods: {
    handleSizeChange() {
      console.log(`每页 ${val} 条`);
    },
    tzHome(){
      this.$router.push({path:'/home'});
    },
    tzLogin(){
      this.$router.push({path:'/login'});
    },
    handleCurrentChange(val) {
      this.tableData = [];
      this.$axios
        .get(
          `https://elm.cangdu.org/bos/orders?offset=${
            (val - 1) * this.limit
          }&limit=20`
        )
        .then((res) => {
          this.tableData = res.data;
          console.log(`当前页: ${val}`);
        });
    },
  },
mounted(){
        this.$axios
      .get("https://elm.cangdu.org/bos/orders?offset=0&limit=20")
      .then((res) => {
        this.tableData = res.data;
        this.tb=this.tableData;
        console.log(this.tableData)
      });
    }
};
</script>
<style scoped>
.block {
  position: relative;
}
.poputs {
  position: absolute;
  top: 55px;
  left: -20px;
  width: 80px;
  height: 60px;
  background-color: #fff;
  box-sizing: border-box;
  box-shadow: 2px 3px 10px -1px #333;
  display: none;
  z-index: 999;
}
.block:hover .poputs {
  display: block;
}
.poputs > div {
  width: 80px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  color: #000;
  cursor: pointer;
}
.poputs > div:hover {
  background-color: #e4e8f1;
  color: #333;
}
</style>